<template> 
<div class="app-container">
    <div class="ces-main">
       



 

 <el-form
        :inline="true"
        :model="Search"
        class="demo-form-inline"
        size="mini"
      >
       <!-- <el-col :xs="10" :sm="8" :lg="6" :xl="4">
        <el-tabs v-model="Search.Status" @tab-click="refresh">
          <el-tab-pane
            v-for="item in cities"
            :label="item.label"
            :name="item.value"
            :key="item.value"
          ></el-tab-pane>
        </el-tabs>
       </el-col> -->
       
      </el-form>
        <v-GetToolBar align="right" :MenuCode="MenuCode"  
        :IsfunEdit='IsfunEdit'
        :Isfunfail='Isfunfail'
        @handeAdd='handeAdd'
        @handleEdit='handleEdit'
        @OpenFindForm='OpenFindForm'
        @handlexportData='handlexportData'
        @IsfunEdit='handleIsfunEdit'
        @IsfunDelete='false'
        ></v-GetToolBar>
     
   <el-form
        :inline="true"
        :model="Search"
        class="demo-form-inline"
        size="mini"
      >


       <el-form-item prop="Relationship" label="订单编号" style="height:25px">
                  <el-input
                    type="“text”"
                    size="small"
                    v-model="OrderAnalysis.OrderNo"
                  ></el-input>
                </el-form-item>

                 <el-form-item prop="Relationship" label="产品编号" style="height:25px">
                  <el-input
                    type="“text”"
                    size="small"
                    v-model="OrderAnalysis.PrdNo"
                  ></el-input>
                </el-form-item>

                 <el-form-item prop="Relationship" label="产品规格" style="height:25px">
                  <el-input
                    type="“text”"
                    size="small"
                    v-model="OrderAnalysis.SPC"
                  ></el-input>
                </el-form-item>
                <el-form-item >
                     <el-form-item >
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-check"
               @click="handleOpen('Sales')"
              >添加订单</el-button>
                </el-form-item>
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-check"
              @click="handleMRPData()"
              >运算</el-button>
                </el-form-item>

       </el-form>

        <ces-table 
        size='mini'
        :isSelection='false'
        :isIndex='true'
        :isSearch='true'
        :isHandle='false'
        :IsfunEdit='IsfunEdit'
        :Isfunfail='Isfunfail'
        :tableData='tableData' 
        :tableCols='tableCols' 
        :Search='Search'
        @refresh="refresh"
        @handleEdit='handleEdit'
        @handleDelete="delData"
        >
        </ces-table>
        </div>

 <!--搜索弹框-->
    <el-dialog
      title="搜索"
      :visible.sync="SearchDialog"
      custom-class="dialogClass"
      class="searchDialog"
      center
      ref="searchDialog"
      :modal="false"
      :close-on-click-modal="true"
    >
      <el-form :model="Search" label-width="90px" ref="searchForm">
       
       <Search-Form 
        ref="form"   :frame="true"
        size='mini'
        labelWidth = '50px' 
        :searchData = 'Search'
         :tableCols = 'tableCols'
        :searchHandle="searchHandle"></Search-Form >
      </el-form>

      <div
        slot="footer"
        :style="{ 'margin-buttom': 0 == 0 ? DialogBtnMargin : DialogBtnMargin }"
      >
        <el-button @click="reform()">重置</el-button>
        <el-button type="primary" @click="refresh()">确 定</el-button>
      </div>
    </el-dialog>

<el-dialog
              v-if="dialogFormOpen"
              :visible.sync="dialogFormOpen"
              :title="销售订单资料"
              
              width="80%"
            >
              <el-form :model="name" label-width="80px" label-position="left">
                <v-FormOpen
                  :ParmType="ParmType"
                  :FormDataInterID=378
                  :SearchData="SearchData"
                  @FunRowAdd="FunrRowsAdd"
                ></v-FormOpen>
              </el-form>
            </el-dialog>


</div>
</template>

<script>


//引入组件

import cesTable from "../Common//table.vue";
import SearchForm from "../Common//Search.vue";
import MianForm from "../Common//form.vue";

import { funDownload,GetTableColsData } from "@/api/Common";
import { getDataList,DeleteForm,MRPAllData} from '@/api/MesPo/OrderAnalysisMrp'; //更改
import vGetToolBar from "../Common/GetToolBar";
import vFormOpen from "../Common/FormOpen";

export default {
  name:"OrderAnalysisMrp",
    data(){
         //表单查询一般分为input，下拉框，和日期，下面是下拉框时的设置下拉信息的情况，我的项目没有用到，但是留着方便看
      
        return {
        MenuCode: "A050506",
        tableData:[],//表格数据
        tableCols:[],//表格列数据
        searchHandle:[],

        IsfunEdit:false,
        Isfunfail:false,
        Search: {
        // 查询条件
        total: 0, // 总记录数
        pageSize: 13, // 一页显示的记录数
        page: 1, // /当前页码
        RNO: "010", // 表编号  根据Controller中对应的表编号 //更改
        jsWhere: "", // 自定义条件
     
       
      }, OrderAnalysis: {
        
        OrderNo:"", 
        PrdNo: "", 
        PrdName:"",  
        SPC: "", 
        
      },SearchData: {
        // 查询条件
        total: 0, // 总记录数
        pageSize: 13, // 一页显示的记录数
        page: 1, // /当前页码
        RNO: "378", // 表编号  根据Controller中对应的表编号 //更改
        jsWhere: " and isnull(Status,0)=2", // 自定义条件
       
      },
       cities: [
          {
          value: "ALL",
          label: "ALL",
        },
        {
          value: "0",
          label: "草稿",
        },
        {
          value: "1",
          label: "审核中",
        },
        {
          value: "2",
          label: "结案",
        },
        {
          value: "3",
          label: "作废",
        },
      ],
       SearchDialog: false,
         DialogBtnMargin: 0,
         dialogVisible: false,
        dialogFormVisible: false,
          dialogFormOpen:false,
         ParmType: "",
         ParmName:"",
          index:0
          
        }
    },

   components:{ //引入组件后注册组件
    cesTable, 
     vGetToolBar,
     SearchForm,
     MianForm,
    
     vFormOpen
   },
   mounted(){
    this.getTableCols()
    this.getDataList()
   },
    methods:{
         //搜索重置
    refresh() {
      this.getDataList();
    },
     reform() {
       this.Search = {
        // 查询条件
        // total: 0, // 总记录数
        pageSize: 13, // 一页显示的记录数
        page: 1, // /当前页码
        RNO: "010", // 表编号  根据Controller中对应的表编号 //更改
        jsWhere: "", // 自定义条件
      };
       this.getDataList();
    },
      //读取列配置
        async getTableCols(){
        this.tableCols = []
        const res = await  GetTableColsData({InterID:"417"});//更改
        this.tableCols=res.data;
                  
         },
        async getDataList() {
        const res = await getDataList({ data: JSON.stringify(this.Search) });
        this.tableData = res.data.Table;
       
        //将data 中的数据放到DataList中
        this.Search.total = res.data.Table1[0].RecordCount;
    
    },OpenFindForm() {
      //打开搜索框
      this.SearchDialog = true;
      //计算外边距
      console.log(this.$refs.searchDialog.offsetHeight);
      this.DialogBtnMargin = this.$refs.searchDialog.offsetHeight - 40;
    }, handlexportData() {
      funDownload("417", JSON.stringify(this.Search)); //更改
    }, handleIsfunEdit() {
      this.IsfunEdit=true;
    }, handleIsfunfail() {
       this.Isfunfail=true;
    },async handeAdd() {
      // 新建

      let routeUrl = this.$router.push({
        path: "/MesPo/PoOrdersForm",//更改
        query: { billID: "", IsPostBack: false },
      });
      window.open(routeUrl.path, "_top");
    
    },
    handleOpen(name,index)
    {
      
     
      if(name=="SalesmanName")
      {
      this.ParmType = "SalesmanName"; //传入参数
      this.dialogFormVisible = true;
      }else if(name=="CustomerName")
      {
         this.ParmType = "CustomerName"; //传入参数
        this.dialogCUSTVisible = true;
      }else if(name=="PrdName")
      {
this.rows={
          OrderNo: this.tableData[index].OrderNo,
          Extend1: this.tableData[index].CustomerCode,
          Extend2: this.tableData[index].CustomerName,
        
        };

        this.index =index;
        this.ParmType = "PrdName"; //传入参数
        this.dialogPRDTVisible = true;
      }else if(name=="Sales")
      {
       
          this.ParmType = "Sales"; //传入参数
        this.dialogFormOpen = true;
      }

    },
    FunrRowsAdd: function (Rows, ParmType,index) {
      //添加人员

      this.multipleTable = Rows[0];
      let i=0;
      if (ParmType == "SalesmanName") {
        this.FormData.Salesman = this.multipleTable.UserCode;
        this.FormData.SalesmanName = this.multipleTable.UserName;
        this.dialogFormVisible = false;
      }else if (ParmType == "CustomerName") {
        this.FormData.CustomerCode = this.multipleTable.CUS_NO;
        this.FormData.CustomerName = this.multipleTable.NAME;
         this.dialogCUSTVisible = false;
      }else if(ParmType == "PrdName")
      {


         for (let v of Rows) {

        this.multipleTable = v;


      if(i>0)
      {
        this.tableData.push(this.rows);
     
      }
   this.tableData[index].PrdNo=this.multipleTable.PrdNo;
     this.tableData[index].PrdName=this.multipleTable.PrdName;
     this.tableData[index].SPC=this.multipleTable.SPC;
     this.tableData[index].UT=this.multipleTable.UT;

     if(Rows.length==1)
      {
         this.tableData.push(this.rows);
          this.tableData.splice(index+1, 1);
      }
     index++;
     i++;
     }
      this.$forceUpdate();
  
      this.dialogPRDTVisible = false;
      }else if(ParmType == "Sales")
      {
        
    
    this.OrderAnalysis.OrderNo= this.multipleTable.OrderNo;
    this.OrderAnalysis.PrdNo= this.multipleTable.PrdNo;
    this.OrderAnalysis.SPC= this.multipleTable.SPC;

   
      this.dialogFormOpen = false;
      } 
      
    
     
    },async handleMRPData() {
 

          const loading = this.$loading({
          lock: true,
          text: "运算中...",
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
         const result = await MRPAllData({
          billID: this.OrderAnalysis.OrderNo,
          PrdNo: this.OrderAnalysis.PrdNo,
        });

        if (result.code === 20000) {
        
          this.dialogVisible = false;
          this.$notify({
            title: result.msg,
            dangerouslyUseHTMLString: true,
            message: "",
            type: "success",
          });
        

 this.Search = {
        // 查询条件
        // total: 0, // 总记录数
        pageSize: 13, // 一页显示的记录数
        page: 1, // /当前页码
        RNO: "010", // 表编号  根据Controller中对应的表编号 //更改
        jsWhere: " ",
        OrderNo: this.OrderAnalysis.OrderNo,
         
      };
       this.getDataList();


         
        } else {
          this.$notify({
            title: result.msg,
            dangerouslyUseHTMLString: true,
            message: "",
            type: "error",
          });
        }
    
      loading.close();
      
      },
   async handleEdit(scope) {
      // 修改

       let routeUrl = this.$router.push({
        path: "/MesPo/PoOrdersForm",//更改
        query: { billID: scope.row.POrderNo, IsPostBack: false },
      });
      window.open(routeUrl.href, "_top");

      this.inputName = row.billID;
   
      
    },delData({ $index, row }) {
     this.$confirm('删除操作, 是否继续?', '提示', {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
      })
        .then(async () => {
         
           

            const result = await DeleteForm({

              billID: row.billID,
              types: 1,
              IsPostBack: false,
            });
this.getDataList();
            this.$message({
              type: "success",
              message: result.msg,
            });
          
        })
        .catch((err) => {
          console.error(err);
        });
    },
     
       
  }
}
</script>

<style lang="scss" scoped>

.app-container {
  .EditObjs-table {
    margin-top: 30px;
  }

  .permission-tree {
    margin-bottom: 5px;
  }
}
.searchDialog ::v-deep .el-dialog__header {
  background: #409eff;
}
.searchDialog ::v-deep .el-dialog__title {
  color: #fff;
}
.searchDialog ::v-deep .el-dialog__headerbtn .el-dialog__close {
  color: #fff;
}
</style>